<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios0.18.js"></script>
</head>
<body>
<div id="app">
    <label>
        用户名：
        <input type="text" v-model="username">
    </label><br>
    <label>
        密码：
        <input type="password" v-model="password">
    </label><br>
    <label>
        确认密码：
        <input type="password" v-model="password2">
    </label><br>
    <div style="text-align: center">
        <input type="button" value="注册" @click="regis">
    </div>
</div>
</body>
</html>
<script>
    new Vue({
        el: "#app",
        data: {
            username: "",
            password: "",
            password2: ""
        },
        methods: {
            regis() {
                if (this.password !== this.password2) {
                    alert("两次密码不一致");
                    return;
                }
                axios.post("http://localhost:8080/ssm/user/regis",
                    "username=" + this.username +
                    "&password=" + this.password)
                    .then(function (resp) {
                        console.log(resp);
                        if (resp.data.code === 200) {
                            alert("注册成功");
                            window.location = "login.html";
                        } else {
                            alert(resp.data.msg);
                        }
                    });
            }
        }
    })
</script>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: #f0f0f0;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 80vh;
        margin: 0;
    }
    #app {
        background-color: white;
        padding: 50px;
        border-radius: 5px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    label {
        display: block;
        margin-bottom: 10px;
    }
    input[type="text"], input[type="password"] {
        width: 100%;
        padding: 5px;
        margin-bottom: 10px;
        border: 1px solid #ccc;
        border-radius: 3px;
    }
    input[type="button"] {
        background-color: #4CAF50;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 16px;
    }
    input[type="button"]:hover {
        background-color: #45a049;
    }
</style>
